﻿#pragma once

#include "../../MirObjects/Effect.h"
#include "../../MirControls/MirImageControl.h"
#include "../../MirObjects/UserObject.h"
#include "../../MirControls/MirButton.h"
#include "../../MirControls/MirControl.h"
#include "../../MirControls/MirLabel.h"
#include "../../../Shared/Data/ItemData.h"
#include "../../MirControls/MirTextBox.h"
#include "../../Settings.h"
#include "../../../Shared/Enums.h"
#include "../../MirControls/MirItemCell.h"
#include "../../MirControls/MirAnimatedControl.h"
#include "../../../Shared/Data/GuildData.h"
#include "../../../Shared/Data/ClientData.h"
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <stdexcept>
#include <any>
#include <optional>
#include "../../../bankersrounding.h"
#include "../../../stringhelper.h"

//C# TO C++ CONVERTER NOTE: Forward class declarations:
namespace Client::MirScenes::Dialogs { class ChatHistory; }
namespace Client::MirScenes::Dialogs { class MagicButton; }

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirObjects;
using namespace Client::MirSounds;
using namespace SlimDX;
using namespace SlimDX::Direct3D9;
//C# TO C++ CONVERTER TODO TASK: C# to C++ Converter could not confirm whether this is a namespace alias or a type alias:
//using Font = System::Drawing::Font;
namespace S = ServerPackets;
namespace C = ClientPackets;

using namespace Client::MirScenes::Dialogs;

namespace Client::MirScenes::Dialogs
{
    class MainDialog final : public MirImageControl
    {
    public:
        virtual ~MainDialog()
        {
            delete ExperienceBar;
            delete WeightBar;
            delete LeftCap;
            delete RightCap;
            delete GameShopButton;
            delete MenuButton;
            delete InventoryButton;
            delete CharacterButton;
            delete SkillButton;
            delete QuestButton;
            delete OptionButton;
            delete HealthOrb;
            delete HealthLabel;
            delete ManaLabel;
            delete TopLabel;
            delete BottomLabel;
            delete LevelLabel;
            delete CharacterName;
            delete ExperienceLabel;
            delete GoldLabel;
            delete WeightLabel;
            delete SpaceLabel;
            delete AModeLabel;
            delete PModeLabel;
            delete SModeLabel;
            delete CustomButton1;
            delete CustomButton2;
        }

        static UserObject *getUser();
        static void setUser(UserObject *value);

        MirImageControl *ExperienceBar, *WeightBar, *LeftCap, *RightCap;
        MirButton *GameShopButton, *MenuButton, *InventoryButton, *CharacterButton, *SkillButton, *QuestButton, *OptionButton;
        MirControl *HealthOrb;
        MirLabel *HealthLabel, *ManaLabel, *TopLabel, *BottomLabel, *LevelLabel, *CharacterName, *ExperienceLabel, *GoldLabel, *WeightLabel, *SpaceLabel, *AModeLabel, *PModeLabel, *SModeLabel;

        MirButton *CustomButton1, *CustomButton2;

        bool getHPOnly() const;

        MainDialog();

        void Process();

    private:
        void Label_SizeChanged(std::any sender, EventArgs *e);

        void HealthOrb_BeforeDraw(std::any sender, EventArgs *e);

        void ExperienceBar_BeforeDraw(std::any sender, EventArgs *e);

        void WeightBar_BeforeDraw(std::any sender, EventArgs *e);
    };
    class ChatDialog final : public MirImageControl
    {
    public:
        std::vector<ChatHistory*> FullHistory = std::vector<ChatHistory*>();
        std::vector<ChatHistory*> History = std::vector<ChatHistory*>();
        std::vector<MirLabel*> ChatLines = std::vector<MirLabel*>();

        std::vector<ChatItem*> LinkedItems = std::vector<ChatItem*>();
        std::vector<MirLabel*> LinkedItemButtons = std::vector<MirLabel*>();

        MirButton *HomeButton, *UpButton, *EndButton, *DownButton, *PositionBar;
        MirImageControl *CountBar;
        MirTextBox *ChatTextBox;
        System::Drawing::Font *ChatFont = new System::Drawing::Font(Settings::FontName, 8.0F);
        std::string LastPM = std::string::Empty;

        int StartIndex = 0, LineCount = 4, WindowSize = 0;
        std::string ChatPrefix = "";

        bool Transparent = false;

        virtual ~ChatDialog()
        {
            delete HomeButton;
            delete UpButton;
            delete EndButton;
            delete DownButton;
            delete PositionBar;
            delete CountBar;
            delete ChatTextBox;
            delete ChatFont;
        }

        ChatDialog();

        void SetChatText(const std::string &newText);

    private:
        void ChatTextBox_KeyPress(std::any sender, KeyPressEventArgs *e);

        void PositionBar_OnMoving(std::any sender, MouseEventArgs *e);

    public:
        void ReceiveChat(const std::string &text, ChatType type);

        void Update();

    private:
        void ChatLink(const std::string &name, unsigned long long uniqueID, Point *p);


        void ChatPanel_KeyDown(std::any sender, KeyEventArgs *e);
        void ChatPanel_KeyPress(std::any sender, KeyPressEventArgs *e);
        void ChatPanel_MouseWheel(std::any sender, MouseEventArgs *e);
        void ChatTextBox_KeyUp(std::any sender, KeyEventArgs *e);
        void ChatTextBox_KeyDown(std::any sender, KeyEventArgs *e);


    public:
        void ChangeSize();

        void UpdateBackground();

    public:
        class ChatHistory
        {
        public:
            std::string Text;
            Color *ForeColour, *BackColour;
            ChatType Type = static_cast<ChatType>(0);
            virtual ~ChatHistory()
            {
                delete ForeColour;
                delete BackColour;
            }

        };
    };
    class ChatControlBar final : public MirImageControl
    {
    public:
        MirButton *SizeButton, *SettingsButton, *NormalButton, *ShoutButton, *WhisperButton, *LoverButton, *MentorButton, *GroupButton, *GuildButton, *ReportButton, *TradeButton;

        virtual ~ChatControlBar()
        {
            delete SizeButton;
            delete SettingsButton;
            delete NormalButton;
            delete ShoutButton;
            delete WhisperButton;
            delete LoverButton;
            delete MentorButton;
            delete GroupButton;
            delete GuildButton;
            delete ReportButton;
            delete TradeButton;
        }

        ChatControlBar();

        void ToggleChatFilter(const std::string &chatFilter);
    };
    class InventoryDialog final : public MirImageControl
    {
    public:
        MirImageControl *WeightBar;
        std::vector<MirImageControl*> LockBar = std::vector<MirImageControl*>(10);
        std::vector<MirItemCell*> Grid;
        std::vector<MirItemCell*> QuestGrid;

        MirButton *CloseButton, *ItemButton, *ItemButton2, *QuestButton, *AddButton;
        MirLabel *GoldLabel, *WeightLabel;

        virtual ~InventoryDialog()
        {
            delete WeightBar;
            delete CloseButton;
            delete ItemButton;
            delete ItemButton2;
            delete QuestButton;
            delete AddButton;
            delete GoldLabel;
            delete WeightLabel;
        }

        InventoryDialog();

    private:
        void Button_Click(std::any sender, EventArgs *e);

        void Reset();



    public:
        void RefreshInventory();

        void RefreshInventory2();

        void Process();


    private:
        void WeightBar_BeforeDraw(std::any sender, EventArgs *e);


    public:
        MirItemCell *GetCell(unsigned long long id);

        MirItemCell *GetQuestCell(unsigned long long id);

        void DisplayItemGridEffect(unsigned long long id, int type = 0);
    };
    class BeltDialog final : public MirImageControl
    {
    public:
        std::vector<MirLabel*> Key = std::vector<MirLabel*>(6);
        MirButton *CloseButton, *RotateButton;
        std::vector<MirItemCell*> Grid;

        virtual ~BeltDialog()
        {
            delete CloseButton;
            delete RotateButton;
        }

        BeltDialog();

    private:
        void BeltPanel_BeforeDraw(std::any sender, EventArgs *e);

    public:
        void Flip();


        MirItemCell *GetCell(unsigned long long id);
    };
    class SkillBarDialog final : public MirImageControl
    {
    private:
        MirButton *const _switchBindsButton;

    public:
        bool AltBind = false;
        bool HasSkill = false;
        unsigned char BarIndex = 0;

        //public bool TopBind = !Settings.SkillMode;
        std::vector<MirImageControl*> Cells = std::vector<MirImageControl*>(8);
        std::vector<MirLabel*> KeyNameLabels = std::vector<MirLabel*>(8);
        MirLabel *BindNumberLabel = new MirLabel();

        std::vector<MirAnimatedControl*> CoolDowns = std::vector<MirAnimatedControl*>(8);

        virtual ~SkillBarDialog()
        {
            delete _switchBindsButton;
            delete BindNumberLabel;
        }

        SkillBarDialog();

    private:
        void SkillBar_OnMoving(std::any sender, MouseEventArgs *e);

        std::string GetKey(int barindex, int i);


        void MagicKeyDialog_BeforeDraw(std::any sender, EventArgs *e);

    public:
        void Update();


        void Process();

    private:
        void ProcessSkillDelay();

    public:
        void Show() override;

        void Hide() override;
    };
    class CharacterDialog final : public MirImageControl
    {
    public:
        MirButton *CloseButton, *CharacterButton, *StatusButton, *StateButton, *SkillButton;
        MirImageControl *CharacterPage, *StatusPage, *StatePage, *SkillPage, *ClassImage;

        MirLabel *NameLabel, *GuildLabel, *LoverLabel;
        MirLabel *ACLabel, *MACLabel, *DCLabel, *MCLabel, *SCLabel, *HealthLabel, *ManaLabel;
        MirLabel *CritRLabel, *CritDLabel, *LuckLabel, *AttkSpdLabel, *AccLabel, *AgilLabel;
        MirLabel *ExpPLabel, *BagWLabel, *WearWLabel, *HandWLabel, *MagicRLabel, *PoisonRecLabel, *HealthRLabel, *ManaRLabel, *PoisonResLabel, *HolyTLabel, *FreezeLabel, *PoisonAtkLabel;
        MirLabel *HeadingLabel, *StatLabel;
        MirButton *NextButton, *BackButton;

        std::vector<MirItemCell*> Grid;
        std::vector<MagicButton*> Magics;

        int StartIndex = 0;

        virtual ~CharacterDialog()
        {
            delete CloseButton;
            delete CharacterButton;
            delete StatusButton;
            delete StateButton;
            delete SkillButton;
            delete CharacterPage;
            delete StatusPage;
            delete StatePage;
            delete SkillPage;
            delete ClassImage;
            delete NameLabel;
            delete GuildLabel;
            delete LoverLabel;
            delete ACLabel;
            delete MACLabel;
            delete DCLabel;
            delete MCLabel;
            delete SCLabel;
            delete HealthLabel;
            delete ManaLabel;
            delete CritRLabel;
            delete CritDLabel;
            delete LuckLabel;
            delete AttkSpdLabel;
            delete AccLabel;
            delete AgilLabel;
            delete ExpPLabel;
            delete BagWLabel;
            delete WearWLabel;
            delete HandWLabel;
            delete MagicRLabel;
            delete PoisonRecLabel;
            delete HealthRLabel;
            delete ManaRLabel;
            delete PoisonResLabel;
            delete HolyTLabel;
            delete FreezeLabel;
            delete PoisonAtkLabel;
            delete HeadingLabel;
            delete StatLabel;
            delete NextButton;
            delete BackButton;
        }

        CharacterDialog();

        void Show() override;

        void Hide() override;

        void ShowCharacterPage();

    private:
        void ShowStatusPage();

        void ShowStatePage();

    public:
        void ShowSkillPage();

    private:
        void ClearCoolDowns();

        void RefreshInterface();

    public:
        MirItemCell *GetCell(unsigned long long id);

    };
    class MiniMapDialog final : public MirImageControl
    {
    public:
        MirImageControl *LightSetting, *NewMail;
        MirButton *ToggleButton, *BigMapButton, *MailButton;
        MirLabel *LocationLabel, *MapNameLabel;
    private:
        float _fade = 1.0F;
        bool _bigMode = true;

    public:
        MirLabel *AModeLabel, *PModeLabel;

        std::vector<MirLabel*> QuestIcons = std::vector<MirLabel*>();

        virtual ~MiniMapDialog()
        {
            delete LightSetting;
            delete NewMail;
            delete ToggleButton;
            delete BigMapButton;
            delete MailButton;
            delete LocationLabel;
            delete MapNameLabel;
            delete AModeLabel;
            delete PModeLabel;
        }

        MiniMapDialog();

    private:
        void MiniMapDialog_AfterDraw(std::any sender, EventArgs *e);

        void MiniMap_BeforeDraw(std::any sender, EventArgs *e);

    public:
        void Toggle();

    private:
        void SetSmallMode();

        void SetBigMode();

    public:
        void Process();
    };
    class InspectDialog final : public MirImageControl
    {
    public:
        static std::vector<UserItem*> Items;
        static unsigned int InspectID;

        std::string Name;
        std::string GuildName;
        std::string GuildRank;
        MirClass Class = static_cast<MirClass>(0);
        MirGender Gender = static_cast<MirGender>(0);
        unsigned char Hair = 0;
        unsigned short Level = 0;
        std::string LoverName;

        MirButton *CloseButton, *GroupButton, *FriendButton, *MailButton, *TradeButton, *LoverButton;
        MirImageControl *CharacterPage, *ClassImage;
        MirLabel *NameLabel;
        MirLabel *GuildLabel, *LoverLabel;



        MirItemCell *WeaponCell, *ArmorCell, *HelmetCell, *TorchCell, *NecklaceCell, *BraceletLCell, *BraceletRCell, *RingLCell, *RingRCell, *AmuletCell, *BeltCell, *BootsCell, *StoneCell, *MountCell;

        virtual ~InspectDialog()
        {
            delete CloseButton;
            delete GroupButton;
            delete FriendButton;
            delete MailButton;
            delete TradeButton;
            delete LoverButton;
            delete CharacterPage;
            delete ClassImage;
            delete NameLabel;
            delete GuildLabel;
            delete LoverLabel;
            delete WeaponCell;
            delete ArmorCell;
            delete HelmetCell;
            delete TorchCell;
            delete NecklaceCell;
            delete BraceletLCell;
            delete BraceletRCell;
            delete RingLCell;
            delete RingRCell;
            delete AmuletCell;
            delete BeltCell;
            delete BootsCell;
            delete StoneCell;
            delete MountCell;
        }

        InspectDialog();

        void RefreshInferface();


    };
    class OptionDialog final : public MirImageControl
    {
    public:
        MirButton *SkillModeOn, *SkillModeOff;
        MirButton *SkillBarOn, *SkillBarOff;
        MirButton *EffectOn, *EffectOff;
        MirButton *DropViewOn, *DropViewOff;
        MirButton *NameViewOn, *NameViewOff;
        MirButton *HPViewOn, *HPViewOff;
        MirImageControl *SoundBar, *MusicSoundBar;
        MirImageControl *VolumeBar, *MusicVolumeBar;

        MirButton *CloseButton;


        virtual ~OptionDialog()
        {
            delete SkillModeOn;
            delete SkillModeOff;
            delete SkillBarOn;
            delete SkillBarOff;
            delete EffectOn;
            delete EffectOff;
            delete DropViewOn;
            delete DropViewOff;
            delete NameViewOn;
            delete NameViewOff;
            delete HPViewOn;
            delete HPViewOff;
            delete SoundBar;
            delete MusicSoundBar;
            delete VolumeBar;
            delete MusicVolumeBar;
            delete CloseButton;
        }

        OptionDialog();


        void ToggleSkillButtons(bool Ctrl);

    private:
        void SoundBar_MouseMove(std::any sender, MouseEventArgs *e);

        void SoundBar_BeforeDraw(std::any sender, EventArgs *e);

        void MusicSoundBar_BeforeDraw(std::any sender, EventArgs *e);

    public:
        void MusicSoundBar_MouseUp(std::any sender, MouseEventArgs *e);

    private:
        void MusicSoundBar_MouseMove(std::any sender, MouseEventArgs *e);

        void OptionPanel_BeforeDraw(std::any sender, EventArgs *e);

    };
    class MenuDialog final : public MirImageControl
    {
    public:
        MirButton *ExitButton, *LogOutButton, *HelpButton, *KeyboardLayoutButton, *RankingButton, *CraftingButton, *IntelligentCreatureButton, *RideButton, *FishingButton, *FriendButton, *MentorButton, *RelationshipButton, *GroupButton, *GuildButton;

        virtual ~MenuDialog()
        {
            delete ExitButton;
            delete LogOutButton;
            delete HelpButton;
            delete KeyboardLayoutButton;
            delete RankingButton;
            delete CraftingButton;
            delete IntelligentCreatureButton;
            delete RideButton;
            delete FishingButton;
            delete FriendButton;
            delete MentorButton;
            delete RelationshipButton;
            delete GroupButton;
            delete GuildButton;
        }

        MenuDialog();


    };
    class MagicButton final : public MirControl
    {
    public:
        MirImageControl *LevelImage, *ExpImage;
        MirButton *SkillButton;
        MirLabel *LevelLabel, *NameLabel, *ExpLabel, *KeyLabel;
        ClientMagic *Magic;
        MirAnimatedControl *CoolDown;

        virtual ~MagicButton()
        {
            delete LevelImage;
            delete ExpImage;
            delete SkillButton;
            delete LevelLabel;
            delete NameLabel;
            delete ExpLabel;
            delete KeyLabel;
            delete Magic;
            delete CoolDown;
        }

        MagicButton();

        void Update(ClientMagic *magic);

        void SetDelay();
    };
    class AssignKeyPanel final : public MirImageControl
    {
    public:
        MirButton *SaveButton, *NoneButton;

        MirLabel *TitleLabel;
        MirImageControl *MagicImage;
        std::vector<MirButton*> FKeys;

        ClientMagic *Magic;
        unsigned char Key = 0;

        virtual ~AssignKeyPanel()
        {
            delete SaveButton;
            delete NoneButton;
            delete TitleLabel;
            delete MagicImage;
            delete Magic;
        }

        AssignKeyPanel(ClientMagic *magic);

    private:
        void AssignKeyPanel_BeforeDraw(std::any sender, EventArgs *e);
    };
    class BigMapDialog final : public MirControl
    {
private:
    float ScaleX = 0;
        float ScaleY = 0;

        int BigMap_MouseCoordsProcessing_OffsetX = 0, BigMap_MouseCoordsProcessing_OffsetY = 0;

    public:
        BigMapDialog();

private:
    void UpdateBigMapCoordinates(std::any sender, MouseEventArgs *e);

        void OnBeforeDraw();


    public:
        void Toggle();
    };
    class DuraStatusDialog final : public MirImageControl
    {
    public:
        MirButton *Character;

        virtual ~DuraStatusDialog()
        {
            delete Character;
        }

        DuraStatusDialog();

    };
    class CharacterDuraPanel final : public MirImageControl
    {
    public:
        MirImageControl *GrayBackground, *Background, *Helmet, *Armour, *Belt, *Boots, *Weapon, *Necklace, *RightBracelet, *LeftBracelet, *RightRing, *LeftRing, *Torch, *Stone, *Amulet, *Mount, *Item1, *Item2;

        virtual ~CharacterDuraPanel()
        {
            delete GrayBackground;
            delete Background;
            delete Helmet;
            delete Armour;
            delete Belt;
            delete Boots;
            delete Weapon;
            delete Necklace;
            delete RightBracelet;
            delete LeftBracelet;
            delete RightRing;
            delete LeftRing;
            delete Torch;
            delete Stone;
            delete Amulet;
            delete Mount;
            delete Item1;
            delete Item2;
        }

        CharacterDuraPanel();

        void GetCharacterDura();
        void UpdateCharacterDura(UserItem *item);

        void Hide() override;
        void Show() override;
    };

    class CustomPanel1 final : public MirImageControl
    {
    public:
        MirButton *Button1, *Button2, *Button3;

        std::string AMode, PMode, SMode;

        virtual ~CustomPanel1()
        {
            delete Button1;
            delete Button2;
            delete Button3;
        }

        CustomPanel1(MirControl *parent);

        void Process();

        void Toggle();
    };
}
